package com.xbkj.pgrp.server.model.app;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;
import java.util.Date;

/**
 * 用来记录员工不可用的工作
 */
@Erupt(
        name = "员工请假信息",
        orderBy = "begin_date desc"
)
@Table(name = "pgrp_absence", uniqueConstraints = @UniqueConstraint(columnNames = {"id", "begin_date", "end_date"}))
@Entity
@Setter
@Getter
public class Absence extends HyperModel {

    @ManyToOne
    @JoinColumn(name = "employee", foreignKey = @ForeignKey(name = "none", value= ConstraintMode.NO_CONSTRAINT))
    private Employee employee;

    /**
     * 请假开始时间
     */
    @EruptField(
            views = @View(
                    title = "开始时间"
            ),
            edit = @Edit(title = "开始时间", notNull = true)
    )
    @Column(nullable = false, name = "begin_date", columnDefinition = "DATE")
    private Date beginDate;

    /**
     * 请假结束时间
     */
    @EruptField(
            views = @View(
                    title = "结束时间"
            ),
            edit = @Edit(title = "结束时间", notNull = true)
    )
    @Column(nullable = false, name = "end_date", columnDefinition = "DATE")
    private Date endDate;

    /**
     * 请假天数
     */
    @EruptField(
            views = @View(title = "请假天数", show = true),
            edit = @Edit(title = "请假天数", notNull = true)
    )
    @Column(nullable = false, name = "days")
    private Long days = 0l;
}
